home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group00b.txt
/
000114_icon-group-sender_Thu Oct 26 12:49:26 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2001-01-03
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id e9QJnGO01100
for icon-group-addresses; Thu, 26 Oct 2000 12:49:16 -0700 (MST)
Message-Id: <200010261949.e9QJnGO01100@baskerville.CS.Arizona.EDU>
Date: Thu, 26 Oct 2000 10:05:24 -0700 (PDT)
From: Shamim Mohamed <shamim@drones.com>
To: Bob Ardler <ardler@argonet.co.uk>
Cc: icon-group@cs.arizona.edu
Subject: Re: Yet another Newbie question....
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 1291
>> line ? while tab(upto(&letters)) do move(1)
> Intimidates? Sends you screaming come back awk, come back perl, all
> is forgiven?
No! Don't go back to the dark side!
The ? operator sets up a string scanning environment - a string and
position in it. upto(cset) returns the next position (starting from the
current position) that a member of the cset occurs; and tab(i) sets the
position to i.
So tab(upto(&letters)) moves the position to the next occurrence of a
letter.
move(i) advances the position by i; so move(1) skips over the occurrence
of the letter just found. tab() is absolute, move() is relative. (tab()
and move() also return the piece of the string they just skipped over.)
upto() will fail if it found no more occurrences in the string that are
in the cset; so the while loop makes the whole thing go and terminate
correctly.
There are numerous examples in the books that are in the Icon idiom.
Here's a very common way to find all the words in a line:
line ? while tab(upto(&letters)) do {
word := tab(many(&letters))
... do something interesting with the word....
}
many() is the converse of upto(); it returns the position of the end of
the substring with characters from the cset.
The books explain all this much better than I can!
-s